package com.example.flex;

import com.mybatisflex.crypto.Algorithm;
import com.mybatisflex.crypto.CryptoDAO;
import com.mybatisflex.crypto.data.AsymmetricData;
import com.mybatisflex.crypto.data.DigestData;
import com.mybatisflex.crypto.data.SymmetricData;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class CryptoDAOImpl implements CryptoDAO {

    @Override
    public List<AsymmetricData> asymmetries() {
        AsymmetricData as1 = new AsymmetricData();
        as1.setVersion("v1");
        as1.setAlgorithm(Algorithm.SM2.name());
        as1.setPublicKey("049b121dce51a463a2bc40f8e399bb08cd86dee101723e97992ae03fea7fa32cdca1a223868f67b49cc0ffa9bd4ba9c80144750a980de09a871badbf45a2ff3b2d");
        as1.setPrivateKey("a1a0653c58f133d7be8fae3a69aa1152804cd94e336311adba9a7cf78ba34c23");
        as1.setDefaultVersion(false);

        AsymmetricData as2 = new AsymmetricData();
        as2.setVersion("v2");
        as2.setAlgorithm(Algorithm.RSA.name());
        as2.setPrivateKey("MIICdgIBADANBgkqhkiG9w0BAQEFAASCAmAwggJcAgEAAoGBALs5Wzza6MQE3gr4/yOsvk58dGz+aM6hJc1MT0uMUtmr/AQG9h452dHwAaxgzhIbXdW+gi" +
                "+ItipVtsxBetDaKcxUTzP4JpWG7r" +
                "/lR5Y2FuvI9LBBgl7tRLXZAa7v7mtv20FT7i1yPNQFFQr39AZs5H1uvchcopQeiRqRKwJD5VvbAgMBAAECgYADndbT7E2KrzBPAMyOceZMlPtAdIJo7sqBzK" +
                "/VcLnAhVzax9Rp9NPlDwLZ4RY4vFHncJh2p8D7i4YYGF5UA6I5G9sppTcUe4FsD0" +
                "+m9w2kulpe53F3PmsbJOi6aCHtQSxVjJ6CIBG7nAcGLD0736LiFZUjB6cuboQ8QTn8xalkEQJBAOpxjiCpCddeolVH3uWQeTP6CX8ymbodYC3Po/CjQlutXGNBd89W06r4aIXfam2F" +
                "/iTzS6+QmXvyXvxygKADqzECQQDMcFNQnrdRAavAkufqBoTgJzA+GGEWJnNuOrKiBO+Y/r+EFG3PWlN3IF2/SMwyxB8cB4q14OCeLRzFFl3rJ1zLAkEAnqB80R5u2TlfzyIU7/EEASYh" +
                "/N2I5EPyCq0euLhOMuemxkXKwhB2oYz4c/RJ95cc8XVo9X56S0IgAOGcpCg3UQJAPU86TSUsCKkdnuTvk+lck/RsrVKWWxQw7c" +
                "/AnoIocJOFT9DolZSbD1CvjJwCUP8r7TX9zUmhUw5oYFqy08C8PQJAGKmQjBIyJvBXAId/Kjn+DkbZCE/inXsRfEIkCwesTkWIJHZNYWmS3Ce8Kqv0kuNEcb+bx87H9hIEJnRUrUjSZw" +
                "==");
        as2.setPublicKey("MIGfMA0GCSqGSIb3DQEBAQUAA4GNADCBiQKBgQC7OVs82ujEBN4K+P8jrL5OfHRs/mjOoSXNTE9LjFLZq/wEBvYeOdnR8AGsYM4SG13VvoIviLYqVbbMQXrQ2inMVE8z" +
                "+CaVhu6/5UeWNhbryPSwQYJe7US12QGu7+5rb9tBU+4tcjzUBRUK9/QGbOR9br3IXKKUHokakSsCQ+Vb2wIDAQAB");
        as2.setDefaultVersion(true);
        return List.of(as1, as2);
    }

    @Override
    public List<SymmetricData> symmetries() {
        SymmetricData sd1 = new SymmetricData();
        sd1.setVersion("v1");
        sd1.setAlgorithm(Algorithm.SM4.name());
        sd1.setSecretKey("lJbntMnIGm6ahjra");
        sd1.setDefaultVersion(false);

        SymmetricData sd2 = new SymmetricData();
        sd2.setVersion("v2");
        sd2.setAlgorithm(Algorithm.AES.name());
        sd2.setSecretKey("lJbntMnIGm6ahdra");
        sd2.setDefaultVersion(true);
        return List.of(sd1, sd2);
    }

    @Override
    public List<DigestData> digests() {
        DigestData dd1 = new DigestData();
        dd1.setVersion("v1");
        dd1.setAlgorithm(Algorithm.SM3.name());
        dd1.setSalt("lJbntMnIGm6ahjra");
        dd1.setDefaultVersion(false);

        DigestData dd2 = new DigestData();
        dd2.setVersion("v2");
        dd2.setAlgorithm(Algorithm.MD5.name());
        dd2.setSalt("lJbntMnIGm6ahjra");
        dd2.setDefaultVersion(true);

        return List.of(dd1, dd2);
    }


}
